<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script>
    function draw() {
      var canvas = document.getElementById('canvas')
      var ctx = canvas.getContext('2d')
      var img = new Image()
      img.src = './rhino.jpg'
      img.onload = function() {
        ctx.drawImage(img, 0, 0)
      }

      var zoomctx = document.getElementById('zoom').getContext('2d')
      
      canvas.addEventListener('mousemove', function(event) {
        var x = event.clientX - 10
        var y = event.clientY - 10
        zoomctx.drawImage(canvas, x, y, 10, 10, 0, 0, 200, 200)
      })

      var smoothEvent = function(event) {
        zoomctx.imageSmoothingEnabled = this.checked
      }
      document.getElementById('smoothbtn').addEventListener('change', smoothEvent)
    }
  </script>
</head>
<body onload="draw()">
  <canvas id="canvas" width="300" height="227"></canvas>
  <canvas id="zoom" width="300" height="227"></canvas>
  <p>
    <label for="smoothbtn">
      <input type="checkbox" id="smoothbtn" checked>
      开启反锯齿
    </label>
  </p>
</body>
</html>